home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_068 / mg1b / def.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  13KB  |  422 lines

  1. /*
  2.  * This file is the general header file for all parts
  3.  * of the MicroEMACS display editor. It contains all of the
  4.  * general definitions and macros. It also contains some
  5.  * conditional compilation flags. All of the per-system and
  6.  * per-terminal definitions are in special header files.
  7.  * The most common reason to edit this file would be to zap
  8.  * the definition of CVMVAS or BACKUP.
  9.  */
  10. #include    "sysdef.h"        /* Order is critical.        */
  11. #include    "ttydef.h"
  12. #include    <stdio.h>
  13.  
  14. /*
  15.  * If your system and/or compiler does not support the "void" type
  16.  * then define NO_VOID_TYPE in sysdef.h.  In the absence of some
  17.  * other definition for VOID, the default in that case will be to
  18.  * turn it into an int, which works with most compilers that don't
  19.  * support void.  In the absence of any definition of VOID or
  20.  * NO_VOID_TYPE, the default is to assume void is supported, which
  21.  * should be the case for most modern C compilers.
  22.  */
  23.  
  24. #ifdef NO_VOID_TYPE
  25. #  undef VOID
  26. #  define VOID int            /* Default for no void is int */
  27. #else
  28. #ifndef    VOID
  29. #  define VOID void            /* Just use normal void */
  30. #endif /* VOID */
  31. #endif /* NO_VOID_TYPE */
  32.  
  33. /*
  34.  * Table sizes, etc.
  35.  */
  36. #ifdef    HASH
  37. #define    NSHASH    31            /* Symbol table hash size.    */
  38. #endif
  39. #define    NFILEN    80            /* Length, file name.        */
  40. #define    NBUFN    24            /* Length, buffer name.        */
  41. #ifndef NLINE            /* allow it to be defined in makefile */
  42. #define    NLINE    256            /* Length, line.        */
  43. #endif
  44. #define    NKBDM    256            /* Length, keyboard macro.    */
  45. #define    NPAT    80            /* Length, pattern.        */
  46. #define    HUGE    1000            /* A rather large number.    */
  47. #define NSRCH    128            /* Undoable search commands.    */
  48. #define    NXNAME    64            /* Length, extended command.    */
  49. #define    NKNAME    20            /* Length, key names        */
  50. /*
  51.  * Universal.
  52.  */
  53. #define    FALSE    0            /* False, no, bad, etc.        */
  54. #define    TRUE    1            /* True, yes, good, etc.    */
  55. #define    ABORT    2            /* Death, ^G, abort, etc.    */
  56.  
  57. /*
  58.  * These flag bits keep track of
  59.  * some aspects of the last command. The CFCPCN
  60.  * flag controls goal column setting. The CFKILL
  61.  * flag controls the clearing versus appending
  62.  * of data in the kill buffer.
  63.  */
  64. #define    CFCPCN    0x0001            /* Last command was C-P, C-N    */
  65. #define    CFKILL    0x0002            /* Last command was a kill    */
  66.  
  67. /*
  68.  * File I/O.
  69.  */
  70. #define    FIOSUC    0            /* Success.            */
  71. #define    FIOFNF    1            /* File not found.        */
  72. #define    FIOEOF    2            /* End of file.            */
  73. #define    FIOERR    3            /* Error.            */
  74.  
  75. /*
  76.  * Directory I/O.
  77.  */
  78. #define    DIOSUC    0            /* Success.            */
  79. #define    DIOEOF    1            /* End of file.            */
  80. #define    DIOERR    2            /* Error.            */
  81.  
  82. /*
  83.  * Display colors.
  84.  */
  85. #define    CNONE    0            /* Unknown color.        */
  86. #define    CTEXT    1            /* Text color.            */
  87. #define    CMODE    2            /* Mode line color.        */
  88.  
  89. /*
  90.  * global mode
  91.  */
  92. #define    MBSMAP    0x0001            /* Map bs<->del            */
  93. #define MFLOW    0x0002            /* Use ^^ for ^Q and ^/ for ^S    */
  94. #define    MINDENT    0x0004            /* autoindent            */
  95. #define    MFILL    0x0008            /* fill mode            */
  96. #ifdef    NOTAB
  97. #define MNOTAB    0x0010            /* no tab mode            */
  98. #endif
  99.  
  100. /*
  101.  * Flags for "eread".
  102.  */
  103. #define    EFFUNC    0x0001            /* Autocomplete functions.    */
  104. #define EFBUF    0x0002            /* Autocomplete buffers.    */
  105. #define EFFILE    0x0004            /* " files (maybe someday)    */
  106. #define    EFAUTO    0x0007            /* Some autocompleteion on    */
  107. #define    EFNEW    0x0008            /* New prompt.            */
  108. #define    EFCR    0x0010            /* Echo CR at end; last read.    */
  109.  
  110. /*
  111.  * Flags for "getkey".
  112.  */
  113. #define KQUOTE    0x0001            /* Get raw character        */
  114. #define    KNOMAC    0x0002            /* Don't record for macros    */
  115. #define    KPROMPT 0x0004            /* do delayed prompting        */
  116.  
  117. /*
  118.  * Flags for "ldelete"/"kinsert"
  119.  */
  120.  
  121. #define KNONE    0
  122. #define KFORW    1
  123. #define KBACK    2
  124.  
  125. /*
  126.  * Keys are represented inside using an 11 bit
  127.  * keyboard code. The transformation between the keys on
  128.  * the keyboard and 11 bit code is done by terminal specific
  129.  * code in the "kbd.c" file. The actual character is stored
  130.  * in 8 bits (DEC multinationals work); there is also a control
  131.  * flag KCTRL, a meta flag KMETA, and a control-X flag KCTLX.
  132.  * ASCII control characters are always represented using the
  133.  * KCTRL form. Although the C0 control set is free, it is
  134.  * reserved for C0 controls because it makes the communication
  135.  * between "getkey" and "getkbd" easier. The funny keys get
  136.  * mapped into the C1 control area. The KEY type is typedefed in
  137.  * sysdef.h, as it may depeond on compiler/machine.
  138.  */
  139. #define    NKEYS    2048            /* 11 bit code.            */
  140.  
  141. #define    METACH    0x1B            /* M- prefix,   Control-[, ESC    */
  142. #define    CTMECH    0x1C            /* C-M- prefix, Control-\    */
  143. #define    EXITCH    0x1D            /* Exit level,  Control-]    */
  144. #define    CTRLCH    0x1E            /* C- prefix,    Control-^    */
  145. #define    HELPCH    0x1F            /* Help key,    Control-_    */
  146.  
  147. #define    KCHAR    0x00FF            /* The basic character code.    */
  148. #define    KCTRL    0x0100            /* Control flag.        */
  149. #define    KMETA    0x0200            /* Meta flag.            */
  150. #define    KCTLX    0x0400            /* Control-X flag.        */
  151.  
  152. #define    KFIRST    0x0080            /* First special.        */
  153. #define    KLAST    0x009F            /* Last special.        */
  154.  
  155. #define    KRANDOM    0x0080            /* A "no key" code.        */
  156. #define    K01    0x0081            /* Use these names to define    */
  157. #define    K02    0x0082            /* the special keys on your    */
  158. #define    K03    0x0083            /* terminal.            */
  159. #define    K04    0x0084
  160. #define    K05    0x0085
  161. #define    K06    0x0086
  162. #define    K07    0x0087
  163. #define    K08    0x0088
  164. #define    K09    0x0089
  165. #define    K0A    0x008A
  166. #define    K0B    0x008B
  167. #define    K0C    0x008C
  168. #define    K0D    0x008D
  169. #define    K0E    0x008E
  170. #define    K0F    0x008F
  171. #define    K10    0x0090
  172. #define    K11    0x0091
  173. #define    K12    0x0092
  174. #define    K13    0x0093
  175. #define    K14    0x0094
  176. #define    K15    0x0095
  177. #define    K16    0x0096
  178. #define    K17    0x0097
  179. #define    K18    0x0098
  180. #define    K19    0x0099
  181. #define    K1A    0x009A
  182. #define    K1B    0x009B
  183. #define    K1C    0x009C
  184. #define    K1D    0x009D
  185. #define    K1E    0x009E
  186. #define    K1F    0x009F
  187.  
  188. #ifndef SEOL        /* needed for OSK, where '\r' == '\n' */
  189. #  define SEOL '\n'
  190. #endif
  191.  
  192. /*
  193.  * These flags, and the macros below them,
  194.  * make up a do-it-yourself set of "ctype" macros that
  195.  * understand the DEC multinational set, and let me ask
  196.  * a slightly different set of questions.
  197.  */
  198. #define    _W    0x01            /* Word.            */
  199. #define    _U    0x02            /* Upper case letter.        */
  200. #define    _L    0x04            /* Lower case letter.        */
  201. #define    _C    0x08            /* Control.            */
  202. #define _P    0x10            /* end of sentence punctuation    */
  203.  
  204. #define    ISWORD(c)    ((cinfo[(c)]&_W)!=0)
  205. #define    ISCTRL(c)    ((cinfo[(c)]&_C)!=0)
  206. #define    ISUPPER(c)    ((cinfo[(c)]&_U)!=0)
  207. #define    ISLOWER(c)    ((cinfo[(c)]&_L)!=0)
  208. #define    ISEOSP(c)    ((cinfo[(c)]&_P)!=0)
  209. #define    TOUPPER(c)    ((c)-0x20)
  210. #define    TOLOWER(c)    ((c)+0x20)
  211.  
  212. /*
  213.  * generally useful thing for chars
  214.  */
  215. #define CCHR(x)        ((x)-'@')
  216.  
  217. /*
  218.  * All repeated structures are kept as linked lists of structures.
  219.  * All of these start with a LIST structure (except lines, which
  220.  * have their own abstraction). This will allow for
  221.  * later conversion to generic list manipulation routines should
  222.  * I decide to do that. it does mean that there are four extra
  223.  * bytes per window. I feel that this is an acceptable price,
  224.  * considering that there are usually only one or two windows.
  225.  */
  226. typedef struct LIST {
  227.     union {
  228.         struct SYMBOL    *l_sp;
  229.         struct WINDOW    *l_wp;
  230.         struct BUFFER    *l_bp;
  231.         struct LIST    *l_nxt;
  232.     } l_p;
  233.     char    *l_name;
  234. } LIST;
  235. /*
  236.  * Usual hack - to keep from uglifying the code with lotsa
  237.  * references through the union, we #define something for it.
  238.  */
  239. #define    l_next    l_p.l_nxt
  240.  
  241. /*
  242.  * The symbol table links editing functions
  243.  * to names. Entries in the key map point at the symbol
  244.  * table entry.
  245.  */
  246. typedef    struct    SYMBOL {
  247.     LIST    s_list;            /* List chain.            */
  248.     int    (*s_funcp)();        /* Function.            */
  249. #ifdef    HASH
  250.     short    s_flags;        /* Flags for this symbol    */
  251. #endif
  252. }    SYMBOL;
  253. #define    s_symp    s_list.l_p.l_sp
  254. #define s_name    s_list.l_name
  255. #ifdef    HASH
  256. #define SFEND    0x001            /* End of has list        */
  257. #endif
  258.  
  259. /*
  260.  * There is a window structure allocated for
  261.  * every active display window. The windows are kept in a
  262.  * big list, in top to bottom screen order, with the listhead at
  263.  * "wheadp". Each window contains its own values of dot and mark.
  264.  * The flag field contains some bits that are set by commands
  265.  * to guide redisplay; although this is a bit of a compromise in
  266.  * terms of decoupling, the full blown redisplay is just too
  267.  * expensive to run for every input character. 
  268.  */
  269. typedef    struct    WINDOW {
  270.     LIST    w_list;            /* List header               */
  271.     struct    BUFFER *w_bufp;        /* Buffer displayed in window    */
  272.     struct    LINE *w_linep;        /* Top line in the window    */
  273.     struct    LINE *w_dotp;        /* Line containing "."        */
  274.     struct    LINE *w_markp;        /* Line containing "mark"    */
  275.     short    w_doto;            /* Byte offset for "."        */
  276.     short    w_marko;        /* Byte offset for "mark"    */
  277.     char    w_toprow;        /* Origin 0 top row of window    */
  278.     char    w_ntrows;        /* # of rows of text in window    */
  279.     char    w_force;        /* If NZ, forcing row.        */
  280.     char    w_flag;            /* Flags.            */
  281. }    WINDOW;
  282. #define    w_wndp    w_list.l_p.l_wp
  283. #define w_name    w_list.l_name
  284.  
  285. /*
  286.  * Window flags are set by command processors to
  287.  * tell the display system what has happened to the buffer
  288.  * mapped by the window. Setting "WFHARD" is always a safe thing
  289.  * to do, but it may do more work than is necessary. Always try
  290.  * to set the simplest action that achieves the required update.
  291.  * Because commands set bits in the "w_flag", update will see
  292.  * all change flags, and do the most general one.
  293.  */
  294. #define    WFFORCE    0x01            /* Force reframe.        */
  295. #define    WFMOVE    0x02            /* Movement from line to line.    */
  296. #define    WFEDIT    0x04            /* Editing within a line.    */
  297. #define    WFHARD    0x08            /* Better to a full display.    */
  298. #define    WFMODE    0x10            /* Update mode line.        */
  299.  
  300. /*
  301.  * Text is kept in buffers. A buffer header, described
  302.  * below, exists for every buffer in the system. The buffers are
  303.  * kept in a big list, so that commands that search for a buffer by
  304.  * name can find the buffer header. There is a safe store for the
  305.  * dot and mark in the header, but this is only valid if the buffer
  306.  * is not being displayed (that is, if "b_nwnd" is 0). The text for
  307.  * the buffer is kept in a circularly linked list of lines, with
  308.  * a pointer to the header line in "b_linep".
  309.  */
  310. typedef    struct    BUFFER {
  311.     LIST    b_list;            /* buffer list pointer        */
  312.     struct    BUFFER *b_altb;        /* Link to alternate buffer    */
  313.     struct    LINE *b_dotp;        /* Link to "." LINE structure    */
  314.     struct    LINE *b_markp;        /* The same as the above two,    */
  315.     struct    LINE *b_linep;        /* Link to the header LINE    */
  316.     short    b_doto;            /* Offset of "." in above LINE    */
  317.     short    b_marko;        /* but for the "mark"        */
  318.     char    b_nwnd;            /* Count of windows on buffer    */
  319.     char    b_flag;            /* Flags            */
  320.     char    b_fname[NFILEN];    /* File name            */
  321. }    BUFFER;
  322. #define    b_bufp    b_list.l_p.l_bp
  323. #define b_bname    b_list.l_name
  324.  
  325. #define    BFCHG    0x01            /* Changed.            */
  326. #define    BFBAK    0x02            /* Need to make a backup.    */
  327.  
  328. /*
  329.  * This structure holds the starting position
  330.  * (as a line/offset pair) and the number of characters in a
  331.  * region of a buffer. This makes passing the specification
  332.  * of a region around a little bit easier.
  333.  */
  334. typedef    struct    {
  335.     struct    LINE *r_linep;        /* Origin LINE address.        */
  336.     short    r_offset;        /* Origin LINE offset.        */
  337.     RSIZE    r_size;            /* Length in characters.    */
  338. }    REGION;
  339.  
  340. /*
  341.  * All text is kept in circularly linked
  342.  * lists of "LINE" structures. These begin at the
  343.  * header line (which is the blank line beyond the
  344.  * end of the buffer). This line is pointed to by
  345.  * the "BUFFER". Each line contains a the number of
  346.  * bytes in the line (the "used" size), the size
  347.  * of the text array, and the text. The end of line
  348.  * is not stored as a byte; it's implied. Future
  349.  * additions will include update hints, and a
  350.  * list of marks into the line.
  351.  */
  352. typedef    struct    LINE {
  353.     struct    LINE *l_fp;        /* Link to the next line    */
  354.     struct    LINE *l_bp;        /* Link to the previous line    */
  355.     short    l_size;            /* Allocated size        */
  356.     short    l_used;            /* Used size            */
  357. #ifdef    PCC
  358.     char    l_text[1];        /* A bunch of characters.    */
  359. #else
  360.     char    l_text[];        /* A bunch of characters.    */
  361. #endif
  362. }    LINE;
  363.  
  364. /*
  365.  * The rationale behind these macros is that you
  366.  * could (with some editing, like changing the type of a line
  367.  * link from a "LINE *" to a "REFLINE", and fixing the commands
  368.  * like file reading that break the rules) change the actual
  369.  * storage representation of lines to use something fancy on
  370.  * machines with small address spaces.
  371.  */
  372. #define    lforw(lp)    ((lp)->l_fp)
  373. #define    lback(lp)    ((lp)->l_bp)
  374. #define    lgetc(lp, n)    ((lp)->l_text[(n)]&0xFF)
  375. #define    lputc(lp, n, c)    ((lp)->l_text[(n)]=(c))
  376. #define    llength(lp)    ((lp)->l_used)
  377. #define    ltext(lp)    ((lp)->l_text)
  378.  
  379. /*
  380.  * Externals.
  381.  */
  382. extern    int    thisflag;
  383. extern    int    lastflag;
  384. extern    int    curgoal;
  385. extern    int    epresf;
  386. extern    int    sgarbf;
  387. extern    int    mode;
  388. extern    WINDOW    *curwp;
  389. extern    BUFFER    *curbp;
  390. extern    WINDOW    *wheadp;
  391. extern    BUFFER    *bheadp;
  392. extern    KEY    kbdm[];
  393. extern    KEY    *kbdmip;
  394. extern    KEY    *kbdmop;
  395. extern    KEY    getkey();
  396. extern    char    pat[];
  397. extern    SYMBOL    *symbol[];
  398. extern    SYMBOL    *binding[];
  399. extern    BUFFER    *bfind();
  400. extern    WINDOW    *popbuf();
  401. extern    WINDOW    *wpopup();
  402. extern    LINE    *lalloc();
  403. extern  int    nrow;
  404. extern  int    ncol;
  405. extern    char    *version;
  406. extern    int    ttrow;
  407. extern    int    ttcol;
  408. extern    int    tceeol;
  409. extern    int    tcinsl;
  410. extern    int    tcdell;
  411. extern    char    cinfo[];
  412. extern    char    *keystrings[];
  413. extern    SYMBOL    *symlookup();
  414. VOID        update();
  415. VOID        keyname();
  416. /*
  417.  * Standard I/O.
  418.  */
  419. extern    char    *strcpy();
  420. extern    char    *strcat();
  421. extern    char    *malloc();
  422.